// WndTab.cpp : implementation file
//

#include "stdafx.h"
#include "BBViewer.h"
#include "WndTab.h"


// CWndTab

IMPLEMENT_DYNAMIC(CWndTab, CWnd)

CWndTab::CWndTab()
{
}

CWndTab::~CWndTab()
{
}


BEGIN_MESSAGE_MAP(CWndTab, CWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()



// CWndTab message handlers

int CWndTab::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	LPST_BMP_INFO lpBmpInfo;
	int i;
	for (i=0;i<3;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biTabTime_unchecked+i);
		m_chkTab[0].SetBitmap(i, lpBmpInfo->hbmpImage);
		lpBmpInfo = theApp.BmpInfo.GetAt(biTabEvent_unchecked+i);
		m_chkTab[1].SetBitmap(i, lpBmpInfo->hbmpImage);
	}

	lpBmpInfo = theApp.BmpInfo.GetAt(biTabTime_unchecked);
	if (!m_chkTab[0].Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, lpBmpInfo->uImageID, NULL))
		return -1;

	lpBmpInfo = theApp.BmpInfo.GetAt(biTabEvent_unchecked);
	if (!m_chkTab[1].Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, lpBmpInfo->uImageID, NULL))
		return -1;

	LoadText();

	m_ToolTipCtrl.Create(this);
	m_ToolTipCtrl.Activate(TRUE);

	m_ToolTipCtrl.AddTool(&m_chkTab[0], m_sarrText.GetAt(0));
	m_ToolTipCtrl.AddTool(&m_chkTab[1], m_sarrText.GetAt(1));

	return 0;
}

void CWndTab::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	LPST_WND_POS lpWndPos;
	lpWndPos = theApp.WndPos.GetAt(wpTabTime);
	theApp.SetWindowPosition(&m_chkTab[0], cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpTabEvent);
	theApp.SetWindowPosition(&m_chkTab[1], cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
}

BOOL CWndTab::PreTranslateMessage(MSG* pMsg)
{
	m_ToolTipCtrl.RelayEvent(pMsg);

	return CWnd::PreTranslateMessage(pMsg);
}

long CWndTab::OnCtlMessage(UINT wParam, LONG lParam)
{
	CWnd* pParent = GetParent();
	pParent->PostMessage(WM_CTL_MESSAGE, wParam, lParam);
	return 0;
}

void CWndTab::SetTab(int nIndex)
{
	if (nIndex == 0)
	{
		m_chkTab[0].SetCheck(TRUE);
		m_chkTab[1].SetCheck(FALSE);
	}
	else
	{
		m_chkTab[0].SetCheck(FALSE);
		m_chkTab[1].SetCheck(TRUE);
	}
}

BOOL CWndTab::OnEraseBkgnd(CDC* pDC)
{
	return  FALSE;
	return CWnd::OnEraseBkgnd(pDC);
}

void CWndTab::RefreshLang()
{
	LoadText();

	m_ToolTipCtrl.DelTool(&m_chkTab[0]);
	m_ToolTipCtrl.DelTool(&m_chkTab[1]);
	m_ToolTipCtrl.AddTool(&m_chkTab[0], m_sarrText.GetAt(0));
	m_ToolTipCtrl.AddTool(&m_chkTab[1], m_sarrText.GetAt(1));

}

void CWndTab::LoadText()
{
	m_sarrText.RemoveAll();
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_TIME, KEYNAME_BUTTON_TIME));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_EVENT, KEYNAME_BUTTON_EVENT));
}